package structureUtils

import "errors"

/*
	自实现栈

	capacity == 0	：无容量上限
	触发扩容条件		：size > capacity * 0.75	TODO

*/
type stackInt struct {
	data     []int
	capacity int
	size     int
}

func NewStack(capacity int) *stackInt {
	stk := &stackInt{
		data:     make([]int, capacity),
		capacity: capacity,
		size:     0,
	}
	return stk
}

func (stk *stackInt) Push(elem int) bool {
	if stk.capacity != 0 && stk.size == stk.capacity {
		return false
	}
	if stk.capacity == 0 && stk.size == len(stk.data) {
		stk.data = append(stk.data, elem)
	} else {
		stk.data[stk.size] = elem
	}
	stk.size++
	return true
}

func (stk *stackInt) Pop() (int, error) {
	if stk.capacity != 0 && stk.size == 0 {
		return -1, errors.New("栈为空！")
	}

	elem := stk.data[stk.size]
	stk.size--
	if stk.capacity == 0 {

	} else {
	}
	return elem, nil
}

func (stk *stackInt) IsEmpty() bool {
	return stk.size == 0
}
